package com.tengju.user.infrastructure.repository.sign;

import com.tengju.user.domain.model.archive.sign.SelfCertification;
import com.tengju.user.domain.model.archive.sign.SelfCertificationRepository;
import com.tengju.user.domain.model.archive.sign.SelfCertificationStatus;
import com.tengju.user.domain.model.archive.sign.SelfCertificationType;
import com.tengju.user.domain.model.user.UserIdCode;
import com.tengju.user.domain.shared.AccountId;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.SelfCertificationDO;
import com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.custom.SelfCertificationMapper;
import com.tengju.user.infrastructure.repository.convert.SelfCertificationConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class SelfCertificationRepositoryImpl implements SelfCertificationRepository {

    @Resource
    private SelfCertificationMapper selfCertificationMapper;

    @Override
    public SelfCertification findOne(UserIdCode idCode, AccountId accountId) {
        SelfCertificationDO selfCertificationDO = selfCertificationMapper
                .findOne(idCode.getValue(), accountId.getValue(), SelfCertificationStatus.TERMINATED.getVal());
        return SelfCertificationConvert.convertToModel(selfCertificationDO);
    }

    @Override
    public SelfCertification findOne(UserIdCode idCode) {
        SelfCertificationDO selfCertificationDO = selfCertificationMapper
                .findByIdCode(idCode.getValue(), SelfCertificationStatus.TERMINATED.getVal());
        return SelfCertificationConvert.convertToModel(selfCertificationDO);
    }

    @Override
    public SelfCertification find(UserIdCode idCode, SelfCertificationType type, SelfCertificationStatus notStatus) {
        SelfCertificationDO selfCertificationDO = selfCertificationMapper
                .find(idCode.getValue(), type.getVal(), notStatus.getVal());
        return SelfCertificationConvert.convertToModel(selfCertificationDO);
    }
}
